TWB.New_Module({
	///////////////////////////
	name : "Icons",          //
	author : "enduo",        //
	version : 1.0,           //
	///////////////////////////
	
	Screen : function(){
		return (TWB.URL().match(/screen=(\w+)/)||[0,null])[1];
	},
	Mode : function(){
		return (TWB.URL().match(/mode=(\w+)/)||[0,null])[1];
	},
	GoTo : function(screen,mode,just_url){
		if(!TWB.logged()){
			return alert(TWB.lang("notlogged"));
		}
		
		var url=TWB.URL();
		screen=(typeof screen!="undefined")?screen:null;
		mode=(typeof mode!="undefined")?mode:null;
		if(screen){
			if(TWB.Modules.Icons.Screen()){
				url=url.replace(TWB.Modules.Icons.Screen(),screen);
			}
			else{
				url+="&screen="+screen;
			}
		}
		if(mode){
			if(TWB.Modules.Icons.Mode()){
				if(mode){
					url=url.replace(TWB.Modules.Icons.Mode(),mode);
				}
				else{
					url=url.replace("&mode="+TWB.Modules.Icons.Mode(),"");
				}
			}
			else{
				if(mode){
					url+="&mode="+mode;
				}
			}
		}
		else{
			// Make sure to remove mode in case none is specified 
			url=url.replace(/mode=(\w+)/,"");
		}
		// Add village if not there
		if(!url.match(/village=\w+/)){
			url+="&village="+TWB.Modules.BackNext.GetVil();
		}
		// Remove action
		if(url.match(/&action=/)){
			url=url.replace(/&action=(\w+)/,"");
		}
		// Remove view
		if(url.match(/&view=/)){
			url=url.replace(/&view=(\d+)/,"");
		}
		// Remove from
		if(url.match(/&from=/)){
			url=url.replace(/&from=(\d+)/,"");
		}
		// Remove try
		if(url.match(/&try=/)){
			url=url.replace(/&try=(\w+)/,"");
		}
		if(just_url){
			return url;
		}
		TWB.Load_Url(url);
	},
	Switch : function(){
		var accept=[["overview_villages","overview","map","main","barracks","stable","garage","smith","snob","place","statue","market"],
			    ["Overviews","Overview","Map","Main","Barracks","Stable","Garage","Smith","Snob","Place","Statue","Market"]];
		var s=TWB.Modules.Icons.Screen();
		var i=accept[0].indexOf(s);
		if(i>=0){
			TWB.gei("TWB-IconsList").parentNode.setAttribute("id","TWB-"+accept[1][i]);
		}
	},
	priority : 900,
	init : function(){
		TWB.Processor.start("icon_switch","Modules.Icons.Switch","*",false);
	}
});